import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';

class SwiperPage extends StatefulWidget {
  SwiperPage({Key? key}) : super(key: key);

  @override
  State<SwiperPage> createState() => _SwiperPageState();
}

class _SwiperPageState extends State<SwiperPage> {
  List<Map> imgList = [
    {
      "url":
          "https://pic.netbian.com/uploads/allimg/220406/001517-1649175317d3b0.jpg",
    },
    {
      "url":
          "https://pic.netbian.com/uploads/allimg/220406/001517-1649175317d3b0.jpg",
    },
    {
      "url":
          "https://pic.netbian.com/uploads/allimg/220406/001517-1649175317d3b0.jpg",
    },
    {
      "url":
          "https://pic.netbian.com/uploads/allimg/220406/001517-1649175317d3b0.jpg",
    },
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("轮播图组件演示"),
      ),
      body: Column(
        children: <Widget>[
          Container(
              width: double.infinity,
              // height: 150,
              child: AspectRatio(
                child: new Swiper(
                  itemBuilder: (BuildContext context, int index) {
                    return new Image.network(
                      imgList[index]["url"],
                      fit: BoxFit.fill,
                    );
                  },
                  itemCount: imgList.length,
                  pagination: new SwiperPagination(),
                  loop: true,
                  control: new SwiperControl(),
                  autoplay: true,
                ),
                aspectRatio: 16 / 9,
              )),
          Row(children: <Widget>[Text("我是一个文本")]),
          Container(
              width: double.infinity,
              // height: 150,
              child: AspectRatio(
                child: new Swiper(
                    layout: SwiperLayout.CUSTOM,
                    customLayoutOption:
                        new CustomLayoutOption(startIndex: -1, stateCount: 3)
                            .addRotate(
                                [-45.0 / 180, 0.0, 45.0 / 180]).addTranslate([
                      new Offset(-370.0, -40.0),
                      new Offset(0.0, 0.0),
                      new Offset(370.0, -40.0)
                    ]),
                    itemWidth: 300.0,
                    itemHeight: 200.0,
                    itemBuilder: (context, index) {
                      return new Container(
                        // color: Colors.grey,
                        child: new Center(
                          child: Image.network(
                            imgList[index]["url"],
                            fit: BoxFit.contain,
                          ),
                        ),
                      );
                    },
                    itemCount: imgList.length),
                aspectRatio: 16 / 9,
              )),
        ],
      ),
    );
  }
}
